<template>
	<view class="home">
		<view class="u-bg">
			<image src="../../static/headbackground_personalCenter_2.png"></image>
		</view>
		<view class="content">
			<view class="content-header-jifen">
				<view class="jifen">
					<view class="font-30">当日可用积分</view>
					<view class="font-40">{{data.money}}</view>
				</view>
				<view class="jifen">
					<view class="font-30">消耗{{jf}}积分</view>
					<view class="font-40">
						<u-button shape="circle" type="warning" size="mini" @click="getNumdh()">点击兑换</u-button>
					</view>
				</view>
	<!-- 			<view class="jifen">
					<view class="font-30">兑换现金</view>
					<view class="font-40">
						<u-button shape="circle" type="warning" size="mini" @click="getjiner()">点击兑换</u-button>
					</view>
				</view> -->
			</view>
			<view class="rw-content">
				<view class="tag-content">
					<view class="tag" :class="id == item.Id ? 'select' : ''" v-for="(item,index) in classList"
						:key="index" @click="getrw(item)">{{item.title}}</view>
				</view>
				<view style="margin-top: 110upx;">
					<view class="tag-title">{{selectList.title}}</view>
					<view class="list" v-if="jfList.length > 0" v-for="(item, index) in jfList" :key="index">
						<view class="list-line">
							<view class="rw-list">
								<image :src="item.img ? item.img : '../../static/zan.png'"
									style="width: 70upx;height: 70upx;border-radius: 5upx;"></image>
								<view style="margin-left: 10upx;">
									<view>{{item.name}} <text
											style="font-size: 20upx;color: #DD524D;margin-left: 30upx;position: relative;top: -5upx;">+{{item.money}}积分</text>
									</view>
									<view>光看视频下载获取每日积分</view>
								</view>
							</view>
							<view class="btn-qd" @click="getBut(item)">{{item.biao[0]}}</view>
						</view>
						<u-line style="margin-top: 15upx;" color="#cccccc" />
					</view>
					<view class="no-list" v-if="jfList.length == 0">
						<image src="../../static/zw.png" style="width: 230upx;height: 200upx;"></image>
						<view>暂无可接任务</view>
					</view>
				</view>
			</view>
			<view style="width: 100%;margin: 0 auto;margin-top: 10rpx;">
				<ad style="width: 90%; height:100px !important;position: fixed;bottom: 0;" unit-id="adunit-01ab23ef48e284f3"></ad>
			</view>
			<u-popup v-model="show" mode="center" border-radius="10" width="400" height="300">
				<view style="display: flex;flex-direction: column;align-items: center;justify-content: center;">
					<view style="padding-top: 30upx;">
						<view style="text-align: center;font-size: 30upx;">提示</view>
						<view style="text-align: center;margin-top: 20upx;font-weight: bold;font-size: 35upx;">
							消耗{{jf}}积分兑换</view>
					</view>
					<view style="margin-top: 40upx;">
						<u-button @click="dhcd">立即兑换</u-button>
					</view>
				</view>
			</u-popup>
			<u-popup v-model="imgshow" mode="center" border-radius="10" width="80%" height="550">
				<view style="display: flex;flex-direction: column;align-items: center;justify-content: center;">
					<view style="padding-top: 30upx;">
						<view style="text-align: center;font-size: 35upx;font-weight: bold;">扫码关注公众号获取积分</view>
						<view style="text-align: center;margin-top: 20upx;">
							<image src="https://web.kdk59.top/static/images/jfewm.png" style="width: 400upx; height: 400upx;"></image>
							</view>
					</view>
			
				</view>
			</u-popup>
			<!-- 			<view class="lq-lip">
					<u-button type="primary">主要按钮</u-button>
				</view> -->
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				show: false,
				imgshow:false,
				sn: '',
				num: '',
				status: '',
				statusText: '',
				imei: '',
				value: 1,
				ordersn: '',
				videoAd: null,
				data: {},
				classList: [],
				jfList: [],
				id: '',
				selectList: {},
				jf: '',
				good: {},
				jfopenid: '',
				headimg: '',
				nickname: '',
				userid: 0,
				jftoken: '',
				rwid: 0,
			}
		},
		components: {},
		onShow() {
			// this.getdevice();
			var that = this;
			this.getuserjf()
			this.getjfClass()
			this.getdh()
			this.getdhshop()
			// 在页面onLoad回调事件中创建激励视频广告实例
			if (wx.createRewardedVideoAd) {
				that.videoAd = wx.createRewardedVideoAd({
					adUnitId: 'adunit-8b42d738a458a546' //
				})
				that.videoAd.onLoad(() => {})
				that.videoAd.onError((err) => {})
				that.videoAd.onClose((res) => {
					if (res && res.isEnded) {
						// if(this.sn!=null&&this.ordersn!='ed'){
						this.getdevice();
						// }
					} else {
						uni.showToast({
							title: '未观看完视频,领取失败',
							icon: "error"
						});
					}
				})
			}
		},
		onLoad(e) {


			this.sn = uni.getStorageSync('sn');
			this.userid = uni.getStorageSync('userid');
			this.nickname = uni.getStorageSync('nickname');
			this.headimg = uni.getStorageSync('headimg');
			this.jfopenid = uni.getStorageSync('jfopenid');
			console.log(e);
		},
		mounted() {

		},
		onReachBottom() {
			console.log('99')
		},
		methods: {
			// 获取
			getBut(val) {
				console.log(val);
				this.rwid = val.Id;
				if (val.type == 1) {
					this.$request('', '/api/app/xcx/shipinstatus', 'POST', {}, {}).then(res => {
						if (res.data == 1) {
							this.getstatus();
						} else {
							uni.navigateTo({
								url: '/pages/show/index?url=https://web.kdk59.top/shouquan.html&id=' +
									val.Id + '&st=1&token=' + this.jftoken + '&openid=' + this.jfopenid +
									'&type=1'
							})
						}
					})

				} else if (val.type == 2) {
					uni.navigateTo({
						url: '/pages/show/index?url=https://web.kdk59.top/shouquan.html&id=' + val.Id +
							'&st=1&token=' + this.jftoken + '&openid=' + this.jfopenid + '&type=2'
					})
				}else if (val.type == 4) {
						// this.imgshow=true;
						uni.navigateTo({
							url: '/pages/show/index?url=https://web.kdk59.top/ewm.html&type=4&sn='+this.sn+'&gzhjfid=' + val.Id
						})
				} else {
					
					uni.navigateTo({
						url: '/pages/show/index?url=https://jf2.kdk59.top/index/pro/htmlinfo&id=' + val.Id + '&st=1&token=' + this.jftoken+'&type=3'
					})
				}
			},
			// 获取用户积分
			getuserjf() {
				this.$request('', '/api/app/task/user', 'POST', {
				}, {}).then(res => {
					console.log(res.data)
				
					this.data = res.data
					this.jftoken = res.token.token
					uni.setStorageSync('jfuserInfoList', this.data)
					uni.setStorageSync('jftokenInfo', this.jftoken)
				})
			},
			// 获取积分分类
			getjfClass() {
				this.$request('', '/api/app/task/typelist', 'POST', {}, {}).then(res => {
					this.classList = res.data
					this.id = res.data[0].Id
					this.selectList = res.data[0]
					this.getrw(this.selectList)
				})
			},
			getrw(val) {
				this.$request('', '/api/app/task/list', 'POST', {
					pagesize: 10,
					pagenum: 0,
					type: val.Id
				}, {}).then(res => {
					this.selectList = val
					this.id = val.Id
					this.jfList = res.data
				})
			},
			getdh() {
				this.$request('', '/api/app/task/agentint', 'POST', {
					sn: this.sn
				}, {}).then(res => {
					this.jf = res.data
				})
			},
			getdhshop() {
				this.$request('', '/api/app/task/taskgood', 'POST', {
					sn: this.sn
				}, {}).then(res => {
					this.good = res.data
				})
			},
			getjiner(){
				uni.navigateTo({
					url: '/pages/jf/duihuan'
				})
			},
			getNumdh() {
				// uni.navigateTo({
				// 	url: '/pages/jf/duihuan'
				// })
				// 	return ;
				this.show = true
			},
			dh() {
				this.$request('', '/api/app/task/isit', 'POST', {
					style: this.jf,
					sn: this.sn,
					openid: this.jfopenid,
				}, {}).then(res => {
					this.good = res.data
				})
			},
			dhcd() {
				
				if (!this.sn) {
					uni.showToast({
						title: '请扫设备二维码',
						duration: 2000,
						icon: 'error'
					});
					return ;
				}
				this.$request('', '/api/app/textstatus', 'POST', {
					type:3
				},{
				}).then(res => {	
				// 用户触发广告后，显示激励视频广告.
				if(res.data==1){
				uni.navigateToMiniProgram({
				  appId: 'wx724dceda075a37fc',
				  path: 'pages/duihuan/index?sn='+this.sn+'&user_id='+this.userid+"&good_id="+this.good.id+"&openid="+this.jfopenid+"&token="+uni.getStorageSync('token'),
				  extraData: {
				    sn:this.sn,
					user_id:this.userid,
					good_id:this.good.id,
					openid:this.jfopenid,
					token:uni.getStorageSync('token')
				  },
				  success(res) {
				    // 打开成功
				  }
				})
				}else{
				this.$request('', '/api/app/task/isit', 'POST', {
					sn: this.sn,
					style:15,
					openid:this.jfopenid
				}, {}).then(res => {
					if(res.status==200){
						this.$request('', '/api/app/task/tissue', 'POST', {
							sn: this.sn,
							user_id: this.userid,
							good_id: this.good.id
						}, {}).then(res => {
							if (res.status == 200) {
								uni.showToast({
									title: '出货成功',
									duration: 2000,
									icon: 'success'
								});
								this.show = false
							} else {
								uni.showToast({
									title: '出货失败',
									duration: 2000,
									icon: 'error'
								});
							}
						})
					}else{
						uni.showToast({
							title: res.msg,
							duration: 2000,
							icon: 'error'
						});
					}
				})
				}
				 })

			},
			getdevice() {
				console.log(123);
				this.$request('', '/api/app/task/reward', 'POST', {
					id: this.rwid,
					token: 1,
					openid: this.jfopenid,
					nick_name: this.nickname,
				}, {}).then(res => {
					if (res.status == 200) {
						uni.showToast({
							title: '领取成功',
							icon: "success"
						});
					} else {
						uni.showToast({
							title: '领取失败',
							icon: "error"
						});
					}
				})
			},
			getstatus() {
				var that = this;
				// 用户触发广告后，显示激励视频广告.
				if (that.videoAd) {
					that.videoAd.show().catch(() => {
						// 失败重试
						that.videoAd.load()
							.then(() => that.videoAd.show())
							.catch(err => {
								// that.changeRange()
								uni.showToast({
									title: '视频全部推送完毕，请明日再来',
									icon: "error"
								});
								console.log('激励视频 广告显示失败')
							})
					})
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.lq-lip {
		width: 90%;
	}

	.btn-qd {
		// width: 120upx;
		height: 60upx;
		background-color: rgb(255, 88, 75);
		line-height: 60upx;
		text-align: center;
		color: #FFFFFF;
		border-radius: 20upx;
		padding-left: 10upx;
		padding-right: 10upx;
		font-size: 26upx;
	}

	.font-30 {
		font-size: 28upx;
		color: #FFFFFF;
		font-weight: bold;
		text-align: center;
		letter-spacing: 2upx;
	}

	.font-40 {
		font-size: 40upx;
		color: #FFFFFF;
		font-weight: bold;
		text-align: center;
		margin-top: 5upx;
	}

	.home {
		height: 100vh;
		width: 100%;
		background-color: rgb(242, 241, 239);
	}

	.select {
		background: #FFFFFF !important;
	}

	.u-bg {
		width: 100%;

		image {
			width: 100%;
		}
	}

	.tag {
		width: 200upx;
		height: 100upx;
		line-height: 100upx;
		text-align: center;
		background: rgb(243, 244, 245);
		border-right: 1upx solid #C0C4CC;
	}

	.content {
		width: 100%;
		position: absolute;
		top: 100upx;

		.content-header-jifen {
			display: flex;
			justify-content: space-around;
		}

		.rw-content {
			width: 95%;
			height: 800upx;
			background: #FFFFFF;
			border-radius: 15upx;
			margin: 0 auto;
			margin-top: 30upx;
			overflow: scroll;
			position: relative;

		}

		.tag-content {
			width: 95%;
			display: -webkit-box;
			overflow: scroll;
			position: fixed;
			z-index: 1000;
			border-radius: 15rpx;
		}

		.tag-title {
			margin-top: 30upx;
			font-size: 40upx;
			padding-left: 30upx;
			font-weight: bold;
		}

		.rw-list {
			display: flex;
			padding-left: 20upx;
			align-items: center;
		}

		.list {
			// display: flex;
			// align-items: center;
			// justify-content: space-between;
			padding-right: 30upx;
			padding-left: 30upx;
			margin-top: 20upx;
		}
		.list-line {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-right: 20upx;
			margin-top: 20upx;
			margin-bottom: 20upx;
		}

		.no-list {
			width: 100%;
			height: 550upx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
		}

		.tag-content::-webkit-scrollbar {
			display: none
		}
	}
</style>
